package com.rongshu.view.userInfo.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetBean;
import com.rongshu.view.userInfo.entity.Article;
import com.rongshu.view.userInfo.iview.ArticleView;

import rx.Subscriber;

public class ArticlePresenter extends BasePresenter<ArticleView> {

    public ArticlePresenter(Context context) {
        super(context);
    }

    /**
     * App获取文集名字列表
     */
    public void getAppSerial(int user_id, String isSerial, int pageIndex, int pageSize, String sign) {
        RetorfitService.getAppSerial(user_id, isSerial, pageIndex, pageSize, sign)
                .subscribe(new Subscriber<Article>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Article article) {
                        if (getView() != null) {
                            getView().onArticleList(article);
                        }
                    }
                });
    }

    /**
     * APP修改文集
     */
    public void getUpdateSerial(int user_id, int serial_id, String serial_name, String sign) {
        RetorfitService.getUpdateSerial(user_id, serial_id, serial_name, sign)
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {
                        if (getView() != null) {
                            getView().onUpdateArticle(bean);
                        }
                    }
                });

    }

    /**
     * APP创建文集
     */
    public void getAddSerial(int user_id, String serial_name, String isSerial, String sign) {
        RetorfitService.getAddSerial(user_id, serial_name, isSerial, sign)
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {
                        if (getView() != null) {
                            getView().onAddArticle(bean);
                        }
                    }
                });
    }

    /**
     * APP删除文集
     */
    public void getDeleteSerial(int user_id, int serial_id, String sign) {
        RetorfitService.getDeleteSerial(user_id, serial_id, sign)
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {
                        if (getView() != null) {
                            getView().onDeleteArticle(bean);
                        }
                    }
                });
    }
}
